﻿<Window x:Class="FindInFilesResultsWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:RegexUtility"
        xmlns:regex="clr-namespace:System.Text.RegularExpressions;assembly=System"
        Title="Find in Files Results"
        Height="350"
        Width="525"
        DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}">
    <Grid>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <Menu HorizontalContentAlignment="Right">
            <MenuItem Header="Copy to Clipboard">
                <MenuItem Header="Copy File List to Clipboard"
                          Command="{Binding CopyFileListToClipboard}" />
                <MenuItem Header="Copy File List and Line Numbers to Clipboard"
                          Command="{Binding CopyLineNumbersToClipboard}" />
                <MenuItem Header="Copy File List, Line Numbers and Match Contents to Clipboard"
                          Command="{Binding CopyMatchContentsToClipboard}" />
            </MenuItem>
        </Menu>

        <TreeView ItemsSource="{Binding MatchResults}"
                  Grid.Row="1">
            <TreeView.Resources>

                <HierarchicalDataTemplate DataType="{x:Type local:DirectoryGroup}"
                                          ItemsSource="{Binding FileMatches}">
                    <TextBlock Text="{Binding Path=RelativePath}" />
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type local:FileMatch}"
                                          ItemsSource="{Binding Snippets}">
                    <Expander Header="{Binding Path=FileInfo.Name}">
                        <Grid Margin="24,0,0,0"
                              Background="White">
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>

                            <TextBlock Text="Full Name: "
                                       Grid.Row="0"
                                       Grid.Column="0" />
                            <TextBlock Text="{Binding Path=FileInfo.FullName}"
                                       Grid.Row="0"
                                       Grid.Column="1" />

                            <TextBlock Text="Created: "
                                       Grid.Row="1"
                                       Grid.Column="0" />
                            <TextBlock Text="{Binding Path=FileInfo.CreationTime, StringFormat='{}{0:MM/dd/yy hh:mm:ss tt}'}"
                                       Grid.Row="1"
                                       Grid.Column="1" />

                            <TextBlock Text="Modified: "
                                       Grid.Row="2"
                                       Grid.Column="0" />
                            <TextBlock Text="{Binding Path=FileInfo.LastWriteTime, StringFormat='{}{0:MM/dd/yy hh:mm:ss tt}'}"
                                       Grid.Row="2"
                                       Grid.Column="1" />

                            <TextBlock Text="File Size: "
                                       Grid.Row="3"
                                       Grid.Column="0" />
                            <TextBlock Text="{Binding Path=FileInfo.Length, StringFormat='{}{0:0,0} bytes'}"
                                       Grid.Row="3"
                                       Grid.Column="1" />
                        </Grid>
                    </Expander>
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type local:FileMatchSnippet}"
                                          ItemsSource="{Binding MatchResult.Details}">
                    <Expander>
                        <Expander.Header>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="Match at Line " />
                                <TextBlock Text="{Binding Path=Line}" />
                                <TextBlock Text=", Column " />
                                <TextBlock Text="{Binding Path=Column}" />
                            </StackPanel>
                        </Expander.Header>
                        <TextBox Text="{Binding Path=MatchResult.Match.Value, Mode=OneWay}"
                                 IsReadOnly="True" />
                    </Expander>
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type local:MatchResultDetail}"
                                          ItemsSource="{Binding Items}">
                    <TextBlock Text="{Binding Title}" />
                </HierarchicalDataTemplate>

                <DataTemplate DataType="{x:Type regex:Capture}">
                    <TextBlock Text="Capture" />
                </DataTemplate>

                <DataTemplate DataType="{x:Type regex:Group}">
                    <TextBlock Text="Group" />
                </DataTemplate>

            </TreeView.Resources>
        </TreeView>

    </Grid>
</Window>

    